package net.tensor.tensor.oauth.server.service;

import net.tensor.tensor.oauth.server.entity.Client;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.oauth2.provider.ClientDetails;
import org.springframework.security.oauth2.provider.ClientDetailsService;
import org.springframework.security.oauth2.provider.ClientRegistrationException;
import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.Set;

/**
 * @author Q
 */
@Service
public class ClientDetailsServiceImpl implements ClientDetailsService {

    @Override
    public ClientDetails loadClientByClientId(String s) throws ClientRegistrationException {
        Client client=new Client();

        client.setClientId("q");

        client.setSecret(new BCryptPasswordEncoder().encode("q"));

        Set<String> authorizedTypes= new HashSet<>();
        authorizedTypes.add("authorization_code");
        authorizedTypes.add("refresh_token");
        client.setAuthorizedGrantTypes(authorizedTypes);

        client.setScoped(true);

        Set<String> authorizedTypes1= new HashSet<>();
        authorizedTypes1.add("read_user_info");
        client.setScopes(authorizedTypes1);

        Set<String> authorizedTypes2= new HashSet<>();
        authorizedTypes2.add("resource1");
        client.setResourceIds(authorizedTypes2);

        Set<String> authorizedTypes3= new HashSet<>();
        authorizedTypes3.add("http://192.168.0.169:9001/callback");
        client.setRegisteredRedirectUri(authorizedTypes3);

        client.setAutoApprove(false);
        return client;
    }
}
